package cn.kgc.javaweb.servlet.listener;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author: mosin
 * @version: v1.0  2022/11/6
 * application域对象的监听器
 *2.监听域对象中值的改变
 * ServletContextAttributeListener
 *
 */
@WebListener
public class ApplicationAttributeListener implements ServletContextAttributeListener {

    // application对象中有值添加 自动调用该方法
    @Override
    public void attributeAdded(ServletContextAttributeEvent event) {
        String name = event.getName();
        System.out.println("name = " + name);
        Object value = event.getValue();
        System.out.println("value = " + value);
        System.out.println("application attributeAdded");
    }

    // application对象中有值被删除  自动调用该方法
    @Override
    public void attributeRemoved(ServletContextAttributeEvent event) {
        System.out.println("application attributeRemoved");
    }

    // application对象中有值替换   自动调用该方法
    @Override
    public void attributeReplaced(ServletContextAttributeEvent event) {
        System.out.println("  application attributeReplaced");
    }
}
